<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>连字符转小驼峰命名工具</title>
    <style>
        /* 页面整体布局 */
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        /* 内容框 */
        .container {
            background-color: white;
            padding: 30px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            border-radius: 10px;
            width: 100%;
            max-width: 450px;
            text-align: center;
        }

        /* 标题 */
        h1 {
            font-size: 28px;
            color: #333;
            margin-bottom: 20px;
        }

        /* 输入框样式 */
        input {
            width: 100%;
            padding: 12px;
            margin: 10px 0;
            font-size: 16px;
            border: 1px solid #ddd;
            border-radius: 8px;
            background-color: #f9f9f9;
            box-sizing: border-box;
            transition: border-color 0.3s;
        }

        /* 获取焦点时，输入框的边框颜色 */
        input:focus {
            border-color: #4CAF50;
            outline: none;
        }

        /* 按钮样式 */
        button {
            padding: 14px;
            font-size: 18px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.3s;
            width: 100%;
        }

        button:hover {
            background-color: #45a049;
        }

        /* 结果输出框 */
        .result {
            margin-top: 20px;
        }

        /* 结果输出框只读样式 */
        #camelCaseOutput {
            background-color: #f0f0f0;
            cursor: not-allowed;
            color: #333;
        }

        /* 错误提示 */
        .alert {
            color: #e74c3c;
            font-size: 16px;
            margin-top: 10px;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>连字符转小驼峰命名工具</h1>

        <!-- 输入框：让用户输入带有连字符的字符串 -->
        <input type="text" id="hyphenInput" placeholder="请输入带有连字符的字符串，如：example-string-case">

        <!-- 按钮：点击后进行转换 -->
        <button id="convertBtn">转换为小驼峰命名</button>

        <!-- 输出框：显示转换后的小驼峰命名 -->
        <div class="result">
            <label for="camelCaseOutput">转换结果：</label>
            <input type="text" id="camelCaseOutput" readonly>
        </div>

        <!-- 错误提示区域 -->
        <div id="alertMessage" class="alert"></div>
    </div>

    <script>
        // 这个函数实现了将带有连字符的字符串转为小驼峰命名的功能
        const hyphenToLowerCamelCase = (arg, hyphen = '-') => {
            let arr = arg.split(hyphen); // 先按连字符分隔字符串
            for (let i = 1; i < arr.length; i++) {
                arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].substring(1); // 转换后面的单词首字母大写
            }
            return arr.join(''); // 重新组合成字符串
        }

        // 获取相关DOM元素
        const convertBtn = document.getElementById('convertBtn');
        const hyphenInput = document.getElementById('hyphenInput');
        const camelCaseOutput = document.getElementById('camelCaseOutput');
        const alertMessage = document.getElementById('alertMessage');

        // 绑定按钮点击事件
        convertBtn.addEventListener('click', () => {
            const hyphenText = hyphenInput.value.trim();
            if (hyphenText === '') {
                alertMessage.textContent = '请输入一个有效的带连字符的字符串！';
                camelCaseOutput.value = ''; // 清空输出框
            } else {
                alertMessage.textContent = ''; // 清空警告
                const camelCaseText = hyphenToLowerCamelCase(hyphenText);
                camelCaseOutput.value = camelCaseText; // 显示转换结果
            }
        });
    </script>
</body>

</html>